package org.despair2D.ui 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import org.despair2D.renderer.display.DisplayUtil;
	import org.despair2D.ui.puppet.DisplayObjectContainerPuppet;
	import org.despair2D.ui.supportClasses.AbstractRange;
	
	import org.despair2D.core.ns_despair;
	use namespace ns_despair;
	
	
public class FrameRange extends AbstractRange 
{
	
	public function FrameRange( movieClipData:*, v:Number = 0, min:Number = 0, max:Number = 100 ) 
	{
		super(v, min, max);
		
		m_movieClip = DisplayUtil.createMovieClip(movieClipData)
		this.createDisplayObjectContainerPuppet(true).addChild(m_movieClip)
		m_range.binding(____onRangeChange)
	}
	
	
	
	
	override ns_despair function ____onRangeChange() : void
	{
		this.updateValue()
		super.____onRangeChange()
	}
	
	
	final ns_despair function updateValue() : void
	{
		var r:Number, n:Number
		
		r  =  m_movieClip.totalFrames * m_range.ratio
		n  =  int(r)
		
		m_movieClip.gotoAndStop((r != 0) ? (r != n ? n + 1 : n) : 1)
	}
	
	
	override ns_despair function recycle() : void
	{
		super.recycle()
		m_movieClip = null
	}
	
	
	
	ns_despair var m_movieClip:MovieClip
}

}